var dustObj = function() {

	this.canvas = document.getElementById("canvas_bg");
	this.ctx = this.canvas.getContext("2d");
	this.width = 0; //canvas 宽
	this.height = 0; // 高
	this.x = []; //x坐标数组
	this.y = []; //y坐标数组
	this.pic = []; //图片路径数组
	this.num = 50; //数量
	this.No = []; //每个的图片地址
	this.amp = []; //每个漂浮物的摆动浮度
	this.alpha; //摆动角度

}

dustObj.prototype.init = function() {
	for (var i = 0; i < 7; i++) {
		this.pic[i] = new Image();
		this.pic[i].src = "../static/img/dust" + i + ".png";
	}
	for (var i = 0; i < this.num; i++) {
		this.x[i] = this.width * Math.random();
		this.y[i] = this.height * Math.random();
		this.No[i] = Math.floor(Math.random() * 7);
		this.amp[i] = 20 + Math.random() * 15;
	}
	this.alpha = 0;
}

dustObj.prototype.draw = function() {
	this.ctx.clearRect(0,0,this.width,this.height);
	this.drawDust(this.ctx);
	

}

dustObj.prototype.drawDust = function(ctx){
	this.alpha += deltaTime * 0.0009; //角度变化
	var l = Math.sin(this.alpha);
	 ctx.save();
	for(var i=0;i<this.num;i++){
		ctx.beginPath();
		ctx.drawImage(this.pic[this.No[i]],this.x[i]+ l * this.amp[i] , this.y[i] );
		
	}	
	ctx.restore();
}

dustObj.prototype.size = function() {
	let scale = window.devicePixelRatio;
	this.width = window.innerWidth;
	this.height = window.innerHeight;

	this.canvas.style.height = this.height + "px";
	this.canvas.style.width = this.width + "px";
	this.canvas.width = this.width * scale;
	this.canvas.height = this.height * scale;
	this.ctx.scale(scale, scale);


}